<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        span{
            width: 100px;font-size: 20px;margin: 50px;display: block;background: pink;text-align: center;cursor: pointer;
            
        }
        #msg{
            width: 300px;height: 150px;background: #ccc;color: white;display: none;
            position: absolute;
        }
        /* #box{
            width: 100px;font-size: 20px;margin: 50px;display: block;background: red;text-align: center;
        } */

    </style>
</head>
<body>
    <span>四小龙1
        <em></em>
    </span>
    <span>四小龙2</span>
    <span>四小龙3</span>
    <span>四小龙4</span>
    <!-- <div id="box"></div> -->
    <div id="msg"></div>
</body>
<script>
    // mouseover    进入
    // mouseout     离开
    // mouseleave   移动
    var ospan=document.querySelectorAll("span");
    var omsg=document.getElementById("msg");
    var arr=["四小龙1四小龙1四小龙1四小龙1四小龙1四小龙1四小龙1四小龙1",
    "四小龙2四小龙2四小龙2四小龙2四小龙2四小龙2四小龙2四小龙2",
    "四小龙3四小龙3四小龙3四小龙3四小龙3四小龙3四小龙3四小龙3",
    "四小龙4四小龙4四小龙4四小龙4四小龙4四小龙4四小龙4四小龙4"]
    // 绑定事件

    for(i=0;i<ospan.length;i++){
        // 自定义ospan的下标
        ospan[i].index=i;
        // 鼠标进入ospan[i]
        ospan[i].onmouseover=function(){
            // omsg显示
            omsg.style.display="block"
            // console.log(this.index);
            // 将数组中当前索引所对应的内容赋值给omsg
            omsg.innerHTML=arr[this.index]
        }
            // 鼠标离开ospan[i]
        ospan[i].onmouseout=function(){
            // omsg隐藏
            omsg.style.display=""
        }
        // 鼠标在ospan[i]中移动
        ospan[i].onmousemove=function(eve){
            // 获取事件对象的兼容处理
            var e=eve||window.event;
            // 让omsg跟随鼠标的移动而移动
            omsg.style.top=e.clientY+10+"px";
            omsg.style.left=e.clientX+10+"px";
        }
        
    }

</script>
</html>